package com.java.advance.clazz.loader;

/**
 * Created by yangminghua on 2019/4/3.
 */
public class InitDemo {

    public static void main(String[] args) throws ClassNotFoundException {
//        System.out.println(Child.a);
//        Parent[] parents = new Parent[10];
//        System.out.println(Const.CON);


//        Class<Dog> dog = Dog.class; //Dog.class并不会触发Dog类的初始化动作。
        //会触发初始化
//        Class<Cat> cat = (Class<Cat>) Class.forName("com.java.advance.clazz.loader.Cat");
        //不会触发初始化
//        Class clazz = Class.forName("com.java.advance.clazz.loader.Cat", false, Cat.class.getClassLoader());

        //不会触发初始化
        new ClassLoader() {
        }.loadClass("com.java.advance.clazz.loader.Cat");
    }
}

class Parent {
    static int a = 100;

    static {
        System.out.println("父类初始化");
    }
}

class Child extends Parent {
    static {
        System.out.println("子类初始化");
    }
}

/**
 * 常量类
 */
class Const {
    static final int CON = 2;

    static {
        System.out.println("Const类初始化");
    }
}

/**
 * 猫
 */
class Cat {
    String name;
    int age;

    static {
        System.out.println("Cat is load");
    }
}

/**
 * 狗
 */
class Dog {
    String name;
    int age;

    static {
        System.out.println("Dog is load");
    }
}
